/**
 * 添加或修改商品标签信息
 * 
 * @param {}
 *            id goodsId
 * @param {}
 *            title
 * @return {}
 */
function addOrUpdGoodsLable(id, title, goodsId) {
	var addOrUpdGoodsLableForm = new Ext.form.FormPanel({
		id : 'addOrUpdGoodsLableForm',
		frame : true,
		layout : "form",
		buttonAlign : 'center',
		monitorValid : true,
		bodyBorder : false,
		fileUpload : true,// 上传文件设置为true
		reader : new Ext.data.JsonReader({
					success : 'success',
					root : 'data'
				}, [{
							name : 'id'
						}, {
							name : 'goodsId'
						}, {
							name: 'goodsName'
						},{
							name : 'lableName'
						}, {
							name : 'orderList'
						}, {
							name : 'lableStatus'
						}, {
							name : 'createdDate'
						}, {
							name : 'createdName'
						}]),

		items : [{
			layout : 'form',
			border : false,
			style : {
				"textAlign" : 'center'
			},
			items : [{
						xtype : 'hidden',
						name : 'id',
						value : id
					}, {
						id : 'goodsLableGoodsId',
						fieldLabel : "<span style='color:#F00'>*</span>商品名称",
						xtype : 'goodsCmb',
						allowBlank : true,
						hiddenName : 'goodsId',
						showValue : true,
						existall : false,
						defaultFirstRow : 1,
						statusArr : [0, 1]
					}, {
						xtype : 'textfield',
						anchor : '100%',
						fieldLabel : "<span style='color:#F00'>*</span>标签名",
						allowBlank : false,
						name : "lableName"
					}, {
						id : 'goodsLableOrder',
						xtype : 'numberfield',
						anchor : '100%',
						fieldLabel : "<span style='color:#F00'>*</span>排序",
						allowBlank : false,
						blankText : '排序不能为空',
						allowDecimals : false,// 禁用小数
						allowNegative : false, // 禁用负数
						minValue : 1,
						name : "orderList"
					},{
						xtype : 'dataDictionaryCmb',
						id : 'goodsLableForm_statusCmb',
						anchor : '100%',
						fieldLabel : "<span style='color:#F00'>*</span>标签状态",
						editable : false,
						autoLoad : true,
						allowBlank : false,
						defaultFirstRow : 1,
						hiddenName : 'lableStatus',
						dictionaryType : PmsUtil.lable_status
					}]
		}],

		buttons : [{
					text : '确定',
					formBind : true,
					handler : function() {
						addOrUpdGoodLable();
					}
				}, {
					text : "取消",
					handler : function() {
						addOrUpdGoodsLableWindow.close();
					}
				}]
	});
	var addOrUpdGoodsLableWindow = new Ext.Window({
				id : 'addOrUpdGoodsLableWindow',
				closeAction : 'close',
				title : title,
				closable : true,
				plain : true,
				modal : true,
				width : 400,
				height : 330,
				draggable: false, // 不可拖动
				resizable:false,  // 不可调整
				buttonAlign : 'center',
				autoDestroy : true,
				layout : 'fit',
				items : [addOrUpdGoodsLableForm],
				listeners : {
					'show' : function() {
						selectGoodsLableUpdById(id);
					},
					'beforeshow' : function() {
						addOrUpdGoodsLableWindow.center();
					}
				}
			});
	return addOrUpdGoodsLableWindow;

};



/**
 * 查询商品标签信息
 * 
 * @param {}
 *            id
 */
function selectGoodsLableUpdById(id) {
	if (id != null && id != "undefined") {
		Ext.getCmp('goodsLableOrder').getEl().up('.x-form-item').setDisplayed(false);
		Ext.getCmp("addOrUpdGoodsLableForm").getForm().load({
			// deferredRender : false,
			url : __ctxPath + "/goodsManager/selectGoodsLableById",
			params : {
				id : id
			},
			method : "POST",
			waitTitle : "请稍候",
			waitMsg : "正在载入数据...",
			root : "data",
			success : function(form, action) {
				var data = action.result.data;
				// 设置状态
				if (data.lableStatus) {
					var lableStatus = Ext.getCmp("goodsLableForm_statusCmb");
					lableStatus.setValue(data.lableStatus); // 隐藏的值
					lableStatus.setRawValue(PmsUtil
							.lableStatus(data.lableStatus));// 显示的值
				}
				// 设置商品名称
				if (data.goodsId != null) {
					var goodsCmb = Ext.getCmp("goodsLableGoodsId");
					goodsCmb.setValue(data.goodsId); // 隐藏的值
					goodsCmb.setRawValue(data.goodsName);// 显示的值
				}
			},
			failure : function(f, g) {
				Ext.MessageBox.show({
							title : "操作信息",
							msg : "数据加载失败!",
							buttons : Ext.MessageBox.OK,
							icon : Ext.MessageBox.ERROR
						});
			}
		});
	}
}
/**
 * 添加或修改商品图片信息
 */
function addOrUpdGoodLable() {
	var goodsLableForm = Ext.getCmp("addOrUpdGoodsLableForm");
	if (goodsLableForm.getForm().isValid()) {
		Ext.Msg.confirm("提示框", "确认要保存商品图片信息吗?", function(button) {
					if (button == "yes") {
						goodsLableForm.getForm().submit({
							url : __ctxPath + '/goodsManager/addOrUpdateGoodsLable',
							waitTitle : "请稍候",
							waitMsg : "正在提交表单，请稍候......",
							failure : function(response, options) {
								var jsonData = Ext.util.JSON
										.decode(options.response.responseText);
								Ext.MessageBox.show({
											title : "错误提示",
											msg : jsonData.data,
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.ERROR
										});
							},
							success : function(response, options) {
								Ext.getCmp('goodsLableOrder').getEl()
										.up('.x-form-item').setDisplayed(true);
								var jsonData = Ext.util.JSON
										.decode(options.response.responseText);
								Ext.MessageBox.show({
											title : "信息提示",
											msg : jsonData.data,
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.INFO
										});
								Ext.getCmp("addOrUpdGoodsLableWindow").close();
								var gridPanel = Ext
										.getCmp('goodsLableManagerGrid');
								if (typeof(gridPanel) != 'undefined') {
									gridPanel.store.reload();
								}
							}
						});
					}
				});
	}
}